//package com.xqboss.chain.bsn;
//
//import com.alibaba.fastjson2.JSONObject;
//import com.reddate.wuhanddc.DDCSdkClient;
//import com.reddate.wuhanddc.dto.ddc.AccountInfo;
//import com.reddate.wuhanddc.listener.SignEventListener;
//import com.reddate.wuhanddc.net.DDCWuhan;
//import jodd.util.StringUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.stereotype.Component;
//import org.web3j.crypto.Credentials;
//import org.web3j.crypto.RawTransaction;
//import org.web3j.crypto.TransactionEncoder;
//import org.web3j.utils.Numeric;
//
////import org.junit.jupiter.api.Test;
//
//@Slf4j
//@Component
//public class AuthorityServiceUtil {
//
//
//    @Value("${custom.nft.accountDID}")
//    String accountDID;
//
//    @Value("${custom.nft.sendAddress}")
//    String sendAddress;
//
//    public static String privateKey;
//
//    public static String getPrivateKey() {
//        return privateKey;
//    }
//
//    @Value("${custom.nft.privateKey}")
//    public void setPrivateKey(String privateKey) {
//        AuthorityServiceUtil.privateKey = privateKey;
//    }
//
//    // set gateway url
//    static {
//        DDCWuhan.setGatewayUrl("https://opbningxia.bsngate.com:18602/api/c1d275f0b45d42db8e4572c41e22edc3/rpc");
//    }
//
//    public static String transactionSignature(String sender, RawTransaction transaction) {
//        // sender: Obtain the private key according to the sender and complete its signature
//        //sender privateKey
//        Credentials credentials = null;
//        if(StringUtil.isNotBlank(sender) && sender.length() == 66){
//            credentials = Credentials.create(sender);
//        }else{
//            credentials = Credentials.create(privateKey);
//        }
//        byte[] signedMessage = TransactionEncoder.signMessage(transaction, 5555, credentials);
//        return Numeric.toHexString(signedMessage);
//    }
//
//    /**
//     * 平台方可以通过调用该方法进行DDC账户信息的创建，上级角色可进行下级角色账户的操作，平台方通过该方法只能添加终端账户。
//     *
//     * @param account   DDC链账户地址
//     * @param accountName   DDC账户对应的账户名称
//     * @return 返回交易哈希
//     * @throws Exception
//     */
//    public String addAccountByOperator(String account, String accountName)  {
//        // sign event listener
//        SignEventListener signEventListener = event -> transactionSignature(event.getSender(), event.getRawTransaction());
//        // ddcSdkClient instantiation
//        DDCSdkClient ddcSdkClient = DDCSdkClient.builder().setSignEventListener(signEventListener).build();
//        try {
//            String leaderDID = "";
//            String txHash = ddcSdkClient.authorityService.addAccountByOperator(sendAddress, account, accountName, accountDID, leaderDID);
//            log.info(txHash);
//            return txHash;
////            assertNotNull(txHash);
//        } catch (Exception e) {
//            e.printStackTrace();
//            log.error(e.getMessage());
//        }
//        return "";
//    }
//
//    public AccountInfo getAccount(String address){
//        SignEventListener signEventListener = event -> transactionSignature(event.getSender(), event.getRawTransaction());
//        AccountInfo accountInfo = null;
//        try{
//            accountInfo = DDCSdkClient.builder().setSignEventListener(signEventListener).build().authorityService.getAccount(address);
//        }catch (Exception e){
//        }
////        assertNotNull(accountInfo);
//        log.info(JSONObject.toJSONString(accountInfo));
//        return accountInfo;
//    }
//
//
//
////
////
////    private static String transactionSignature(String sender, RawTransaction transaction) {
////        // sender: Obtain the private key according to the sender and complete its signature
////
////        //sender privateKey
////        String privateKey = "0x20bd77e9c6c920cba10f4ef3fdd10e0cfbf8a4781292d8c8d61e37458445888";
////        Credentials credentials = Credentials.create(privateKey);
////        byte[] signedMessage = TransactionEncoder.signMessage(transaction, 5555, credentials);
////        return Numeric.toHexString(signedMessage);
////    }
////
////
////
////    @Test
////    public void addAccountByOperator() throws Exception {
////        // sign event listener
////        SignEventListener signEventListener = event -> transactionSignature(event.getSender(), event.getRawTransaction());
////
////        // ddcSdkClient instantiation
////        DDCSdkClient ddcSdkClient = new DDCSdkClient().instance(signEventListener);
////
////        try {
////            String account = "0x24a95d34dcbc74f714031a70b077e0abb3308088";
////            String accountName = "bsn-ddc";
////            String accountDID = "did:bsn:123456112211";
////            String leaderDID = "";
////            String txHash = ddcSdkClient.authorityService.addAccountByOperator(sender, account, accountName, accountDID, leaderDID);
////            log.info(txHash);
//////            assertNotNull(txHash);
////        } catch (DDCException e) {
////            System.out.println(e.getMsg());
////        }
////    }
////
////
////
////    @Test
////    public void updateAccState() throws Exception {
////        String account = "0x24a95d34dcbc74f714031a70b077e0abb3308088";
////
////        String txHash = ddcSdkClient.authorityService.updateAccState(sender, account, AccountState.Active, false);
//////        assertNotNull(txHash);
////        log.info(txHash);
////    }
////
////
////    @Test
////    public void crossPlatformApproval() throws Exception {
////
////        String txHash = ddcSdkClient.authorityService.crossPlatformApproval(sender, "0x24a95d34dcbc74f714031a70b077e0abb3308088", "0x24a95d34dcbc74f714031a70b077e0abb3306066", false);
//////        assertNotNull(txHash);
////        log.info(txHash);
////    }
//
//}
